The officially supported Windows build platform for OpenCPN 4.1 beta to OpenCPN 4.8.8 is Microsoft Visual Studio 2013 Express for Windows Desktop.
It is still possible to perform the build with older versions of Visual Studio - particularly if you are still running Windows XP on your development machine, you cannot install a Visual Studio version newer than 2010. If what you have to do differs from the default VS2013 workflow, it is clearly noted in the instructions below.
Note: Older versions of OpenCPN, up to 4.0, used the VS2010 toolchain and wxWidgets 2.8.
The order of the steps described below really matters. Don't skip any steps not explicitly marked as optional and don't change their order unless you really know what you are doing.
It's an excellent idea to read the whole text first and make sure you understand what it's talking about, especially if you are new to software development.
If you encounter any problems, please get to us in the forum and tell us where you are failing so we can help you and improve these instructions for the others.
Before you go to the support forum and start to complain how much these instructions don't work, try to really follow them, even in the steps where you think you know better. If it still won't help, let us know.
Get Visual Studio 2013 Express for Windows Desktop or Visual Studio 2013 Community Edition (with Update 4) from
If you use Windows XP or Vista, upgrade to Windows 7 or newer or try to use Visual Studio 2010 instead (you will need to build your own set of dependencies).
Install Visual Studio - you can disable all the optional features offered to save some space.
Get the Git installation packages from https://git-for-windows.github.io/
Source Directory Path: C:\\Users[username]\Documents\GitHub\Ocpn Build directory Path: C:\\Users[username]\Documents\GitHub\Ocpn\build
Get the latest CMake installation packages from http://www.cmake.org
Install and let it register in the PATH environment variable
Get the latest POedit installation package from http://www.poedit.net
Get the current version 3.x of the NSIS installer from http://nsis.sourceforge.net/ and install it.
Get the latest 3.0 release from http://wxwidgets.org/downloads/ (at the time of this writing 3.0.2)
Uncompress to your drive (we will assume to C:\wxWidgets-3.0.2 in this text)
Note that git clone of opencpn contains 16 wxWidget files under “source\buildwin\wxWidgets, which are used for making installer packages.(NOT for compiling OpenCPN)
Example of a “Source” Directory under github:
C:\\users[username]\Documents\GitHub\\obeta**source** source <-- Git clone or fetch from/into here source\include <-- Git clone download of Include files source\po <-- Git Internationalization files source\src <-- Git clone download of Source Code source\plugins <-- Git clone plugins from/into here. source\data <-- source of some source\buildwin <-- name_pi binaries & special dlls, exe put here. source\build <-- cmake commands are executed from this directory. source\build\plugins <-- copy name_pi.dll from the directory below to here. source\build\plugins\debug <-- copy compiled debug name_pi.dll from here source\build\plugins\release <-- copy compiled release name_pi.dll from here source\build\release <-- copy buildwin binaries & dlls to here for running release. source\build\release\plugins<--copy release name_pi.dll to here + source\plugins\name_pi\\data*.*.
The source might be named OpenCPN
Note: This assumes that you have Microsoft SDK 7.1A installed on your pc. This was the last SDK that allowed building OpenCPN/wxWidgets for XP. If you do not have SDK 7.1A installed 'nmake' may run but the 'wxWidgets' that are built will not work with XP. You will get a 'not a valid Win32 application' message when trying to run OpenCPN in XP (OpenCPN built with these wxWidgets). So use wxWidgets built with SDK7.1A for compatibility with Windows XP.
Run the Developer Command Prompt for VS2013. Go to your wxWidgets build tree (cd C:\wxWidgets-3.0.2\build\msw) and build both release and debug configurations, compatible with Windows XP
RELEASE VERSION nmake -f makefile.vc BUILD=release SHARED=1 CFLAGS=/D_USING_V120_SDK71_ CXXFLAGS=/D_USING_V120_SDK71_ DEBUG VERSION nmake -f makefile.vc BUILD=debug SHARED=1 CFLAGS=/D_USING_V120_SDK71_ CXXFLAGS=/D_USING_V120_SDK71_
In case you are using Visual Studio 2010, the build commands are:
RELEASE nmake -f makefile.vc BUILD=release SHARED=1 DEBUG nmake -f makefile.vc BUILD=debug SHARED=1
This option is more work and not needed for 99% of people. Really, don't use it.
In order for Cmake to find wxWidgets, you must add your wxWidgets root directory C:$[WXDIR] (for example in place of WXDIR use 'C:\wxWidgets-3.0.2') to your PATH environment variable.
To be able to run debug builds and release builds without install add C:$[WXDIR]\lib\vc_dll to your PATH.
After doing this, you have to restart the running programs (cmd.exe, cmake-gui, VisualStudio etc) to make sure they “see” the changed environment variables.
If you are unsure, restart Windows and everything will be set. If you don't do this you will have problems running your debug builds later.
If you have problems with cmake not finding your wxWidgets installation, try also creating another environment variable called WXWIN with a value of C:$[WXDIR] (for example use 'C:\wxWidgets-3.0.2').
Also, try creating an environment variable called wxWidgets_LIB_DIR=C:$[WXDIR]\lib\vc_dll and wxWidgets_ROOT_DIR=C:$[WXDIR]. Again, don't forget to restart the running programs involved in the build.
Run Developer Command Prompt for VS2013 from Start menu → Programs → Microsoft Visual Studio → Visual Studio Tools
To get the source for the first time, from your local github directory or local git repository issue
git clone git://github.com/OpenCPN/OpenCPN.git
In case of error messages like this one:
"error: unable to create file buildwin/NSIS_Unicode/CopyNSISUnicodeRegKey.bat (Permission denied)"
observed under Windows 8.1, run the command from an Administrator console To update the code you cloned before, cd into the source directory cd OpenCPN and issue
git fetch -–all
Note the Setup Batch File “Git_opencpn.bat” will download and expand OpenCPN_buildwin.7z into source\buildwin.
Get OpenCPN_buildwin.7zand extract the dependencies into your toplevel OpenCPN directory. The dependencies top directory is buildwin and hence the files and dirs will be placed under that directory.
(In case you are using Visual Studio 2010, you must build your own dependencies) and extract the archive into your toplevel OpenCPN source directory created by the clone operation above. The archive contains some binary files needed to link OpenCPN and produce the installer.
In case you need the PDB files for the prebuilt libraries (unlikely, really, if you don't know what for, you don't), get them from here.
When extracting the libraries into the build tree, don't overwrite existing files. This will cause problems with pull requests. The buildwin directory after extraction should look like this:
Directory of C:\\Users[username]\Documents\GitHub\Ocpn\buildwin Directories -------------- crashrpt expat-2.1.0 gtk include NSIS_Unicode vc wxWidgets Files ------------- archive.lib archive.dll liblzma.dll lzma.lib zlib1.dll libcurl.dll libcurl.lib ocpn_gltest1.exe Toolchain-mingw32.cmake
mkdir build
cd build cmake -T v120_xp ..
In case you are using Visual Studio 2010, the command is cmake ..
The normal result:
C:\Users\Frederick\Documents\GitHub\Ocpn\build>cmake -T v120_xp .. -- Building for: Visual Studio 12 2013 -- The C compiler identification is MSVC 18.0.31101.0 -- The CXX compiler identification is MSVC 18.0.31101.0 -- Check for working C compiler using: Visual Studio 12 2013 -- Check for working C compiler using: Visual Studio 12 2013 -- works [removed a large section of output results here] -- Generating done -- Build files have been written to: C:/Users/Frederick/Documents/GitHub/Ocpn/build C:\Users\Frederick\Documents\GitHub\Ocpn\build>
NOTE: This is a good point to Start over again if you mess up copying the necessary files or are having troubles compiling & building. The first reasonable intermediate step is to remove all the files in the build directory and then start over by using cmake -T v120_xp .. from the ..\build directory. That often will solve a configuration problem. Also you could just “git clone” another differently named OpenCPN repository and configure that again.
(in case the previous way was too simple for you)
Run “CMake (cmake-gui)” from Start menu → Programs → Cmake 3.2. Fill in your source and build directories.
source = ………./OpenCPN build = ………./OpenCPN/build
Click on the Configure button.
If you are asked to choose the generator, select “Visual Studio 12” (Or better say, select the version of VS you want to use for your build). The information which appeared is red and the Generate button stays disabled? Just hit Configure again…
Ignore GTK2_GTK_INCLUDE_DIR-NOTFOUND and wxwidgets_wxrc_EXECUTABLE_NOTFOUND.
IMPORTANT suggestion: Use CMAKE GUI tool to configure OpenCPN to verify that wxWidgets_LIB_DIR points to the {root}/lib/vc_dll directory. This check is necessary since the cmake FindWxWidgets module sometimes finds the wrong source and/or build config.
If you are using CMake version 3.0 or later you will get warnings about Policy CMP0043. These can be ignored.
cd build cmake -–build . –-config release
The result output in the prompt window is lengthy because about 700mb of files are being created in the build/release directory from the cmake setup and the src directory C++ code files. The first time this command is run may end in ~50 warnings and possibly some errors, but the second or third time it is run the output should end with 0 Error(s). However Warnings are ok and should not affect operation.
Build succeeded.
0 Warning(s)
0 Error(s)
or issue the command for a “debug” build, from the Source Directory,
cd build cmake –-build . –-config debug
The debug version is similar to compiling for release, but adds a number of files which track processes for the purpose of debugging. The first run will have ~50 warnings. It should also end with 0 Error(s) after several re-runs of the command.
Note that if you don't use the –-config parameter, a debug build is performed.
Wait for the builds to complete.
At this point the build\debug directory has 9 lib files, opencpn.pdb, opencpn.ilk and opencpn.exe and no subdirectories. The build\release directory does not contain opencpn.ilk or opencpn.pdb
C:\\Users[username]\Documents\GitHub\Ocpn\build\debug & \release opencpn.exe opencpn.exp opencpn.ilk (debug directory only) opencpn.pdb (debug directory only) opencpn.lib GARMINHOST.lib MIPMAP.lib NMEA0183.lib S57ENC.lib SYMBOLS.lib TEXCMP.lib WXCURL.lib WXSVG.lib
Neither the release or debug will run properly at this point, because the necessary files and important dlls are not available in several directories. Below we will show you several ways to copy the correct files to these directories.
In Visual Studio, open the solution created by the CMake command earlier (Use the file ../build/OpenCPN.sln). Compile the whole solution or individual projects. You must compile project opencpn before you can compile any plugins (to be fixed in the configuration process)
We need more specifics here for the Nooby, step by step references to menus. It won't be lengthy. Just enough to compile it — Rick Gleason 2017/02/25 16:19
If you want to debug, don't forget to select opencpn as a start-up project. Once this is done, in the Solution Explorer (right panel) the project opencpn will be bold.
If you didn't add the WX DLL path to the PATH environment variable earlier, copy the needed WX DLLs to the build directory (Debug or Release, depending on which version you build). The DLLs can be found in C:${WXDIR}\lib\vc_dll and you will need:
Debug: wxbase30ud_net_vc_custom.dll, wxbase30ud_vc_custom.dll, wxbase30ud_xml_vc_custom.dll, wxmsw30ud_adv_vc_custom.dll, wxmsw30ud_aui_vc_custom.dll, wxmsw30ud_core_vc_custom.dll, wxmsw30ud_gl_vc_custom.dll, wxmsw30ud_html_vc_custom.dll, wxmsw30ud_media_vc_custom.dll, wxmsw30ud_propgrid_vc_custom.dll, wxmsw30ud_qa_vc_custom.dll, wxmsw30ud_ribbon_vc_custom.dll, wxmsw30ud_richtext_vc_custom.dll, wxmsw30ud_stc_vc_custom.dll, wxmsw30ud_webview_vc_custom.dll, wxmsw30ud_xrc_vc_custom.dll
Release: wxbase30u_net_vc_custom.dll, wxbase30u_vc_custom.dll, wxbase30u_xml_vc_custom.dll, wxmsw30u_adv_vc_custom.dll, wxmsw30u_aui_vc_custom.dll, wxmsw30u_core_vc_custom.dll, wxmsw30u_gl_vc_custom.dll, wxmsw30u_html_vc_custom.dll, wxmsw30u_media_vc_custom.dll, wxmsw30u_propgrid_vc_custom.dll, wxmsw30u_qa_vc_custom.dll, wxmsw30u_ribbon_vc_custom.dll, wxmsw30u_richtext_vc_custom.dll, wxmsw30u_stc_vc_custom.dll, wxmsw30u_webview_vc_custom.dll, wxmsw30u_xrc_vc_custom.dll
See 6 - Running below to prepare to run the Debug or Release build (from Visual Studio or otherwse) without “installing” - This involves using the compile setup plus copying certain essential and needed files to proper locations so the compile setup will run Opencpn.
If you skipped the step 3.1 and did not do 3.3 Get the binary dependencies yet, please go back there, otherwise you won't be able to create the package.
Build the PACKAGE project and opencpn_[version]_setup.exe is created in your build directory (replace X with the release and Y with the build number). Use the following command:
cmake –-build . –-target package –-config release
OR after using
cmake –-build . –-config release
Then just type cpack in the MS VStudio command prompt to run the NSIS Install Packager.
This will create a new directory under the build directory called _CPack_Packages . You should find your install package under the NSIS sub-directory
C:\\Users[username]\Documents\GitHub\Ocpn\build\_CPack_Packages\win32\NSIS OR source\build\_CPack_Packages\win32\NSIS
Now you can execute the NSIS Install Package file
..source\build\_CPack_Packages\win32\\NSISopencpn_[version]_setup.exe
to install a recently compiled working version of OpenCPN.
You will also find a subdirectory ..\NSIS\opencpn_[version]_setup with all the files used to create this install package.
If you do not intend to use the “release” NSIS Package Installation “exe” to create your “Release” OpenCPN version, you will need to manually complete the actions shown in this Table for Creation of Operational "Release" Version .
The simple NSIS system command cpack or adding –target package to cmake commands, takes care of all this for you, so use it when you can! It is good for “packaging” Windows installation of Opencpn.
(-move to another section?) Currently the installer packs the DLLs from the git repository into the package. You have to replace them with your custom built DLLs after the installation if you want to experiment with different versions and build settings of the wxWidgets libraries. [
I think this is a side matter to the focus of compiling OpenCPN, which is significant when developing a plugin or working on code. I think it should be moved to its own paragraph for more complete explanation.] — Rick Gleason 2017/02/25 14:58
Both Debugging and running Release (bypassing installation) require certain files to be copied.
There are two choices for setting up & maintaining the build, release and debug directories:
NOTE: Batch files are “Beta”
Maintenance and Updates
When you have git fetched & pulled or changed files, these batch files can be Re-run: config.bat, build.bat, dbbuild.bat, dbcopy.bat as needed before using MS VStudio, Using the NSIS Batch or Running the release version directly without installation.
Remove the ”.doc“ from these batch files before running from the command prompt.
CopyFiles.bat.doc Häkän's single batch file - Another alternative Copyfiles-Hakan.bat.doc Hakan has also provided a useful single batch file which is placed in the source\build directory and executed using the command prompt to copy all the needed files to the various directories. This batch file does not execute any cmake commands (unlike the first Git_opencpn.bat Systme with 6 batch files) NOTE:This batch file has not been tested as completely, so it is really BETA at this point!!
4 Internal Plugins Note about copy of Plugin Release and Debug versions *_pi.dll and *_pi\data folders Both Batch File systems copy the needed files for the 4 internal plugins, following the plugins compilation structure. This includes the data directories and proper files for the 4 internal plugins, for Debug to build\plugins and for Release to build\release\plugins. Please note that the debug folder build\plugins will only run “debug” plugins otherwise there will be an error.
Plugin Data Directories
| Source | Destination | |
| Debug | Copy GitHub\obeta\source\plugins\*_pi\data\*.* | source\build\plugins\*_pi\data |
| Release | Copy GitHub\obeta\source\plugins\*_pi\data\*.* | source\build\plugins\*_pi\data |
Plugin *_pi.DLL Files (note source is different for debug & release)
| Source | Destination | |
| Debug | Copy source\build\plugins\chartdldr_pi\debug\*_.dll | source\build\plugins\*_pi\data |
| Release | Copy source\build\plugins\chartdldr_pi\release\*_.dll | source\build\release\plugins\*_pi\data |
NOTE: These Batch files are “Beta” Still Testing & Checking
Use these batch files for a quicker way to complete Sections 3 through 7. Upon completion use MS VStudio Debug or run OpenCPN /p directly from the source\build\release directory.
Git_opencpn.bat is the first batch file used, it will “git clone opencpn”, get and install the binary dependencies, provided you have Powershell (most Windows OS have it) and 7z installed, execute “cmake -T v120_xp ..” and then call the other batch files to complete the setup.
Git_opencpn.bat will simplify installation once you have completed:
Developed by TransmitterDan and Häkän, modified by rgleason & tested. Read the instructions carefully and use them at your own risk. To start:
The batch files will complete the setup from Step 3 to 7. Then Start Debugging in MS VStudio and and find an NSIS Installation package in source\build provided the prerequisite for 1.5 NSIS is completed. This system has 6 batch files executed from the command prompt. These files are being testing now, still beta.
Once executed you should then be able to use MS VStudio to debug Opencpn After the full installation is completed, re-run config.bat, build.bat, dbbuild.bat as needed.
CopyFiles.bat.doc Häkän's single batch file - Another alternative
Copyfiles-Hakan.bat.doc
Remove the ”.doc“ from these batch files before running from the command prompt.
Hakan has also provided a useful single batch file which is placed in the source\build directory and executed using the command prompt to copy all the needed files to the various directories. This batch file does not execute any cmake commands (unlike the first Git_opencpn.bat Systme with 6 batch files)
NOTE:This batch file has not been tested as completely, so it is really BETA at this point!!
Complete the following.
=== Create two new “uidata” folders ===
Files from source/src/bitmaps to uidata ---------------------------------------- styles.xml toolicons_traditional.png toolicons_journeyman.png toolicons_journeyman_flat.png iconAll.png iconMinimum.png iconRMinus.png iconRPlus.png iconStandard.png 3 SVG Directories and files from source/data/svg to uidata ----------------------------------------------------------- journeyman journeyman_flat traditional Styles (custom style files from source/styles to uidata) ---------------------------------------------------------- Copy the individual style.xml files into uidata
Copy the files and folders listed above
Shortcut: If you have run the NSIS Install Package “cpack”, just copy ..build\_CPack_Packages\win32\NSIS\opencpn_[version]_setup\uidata to the folder.
Six directories from source\data -------------------------------- doc sounds tcdata wvsdata gshhs s57data
Copy the six Data folders above from source\data
11 Dll files and Individual files from various locations -------------------------------------------------------- Individual files From zlib1.dll source\buildwin\zlib1.dll libcurl.dll source\buildwin\libcurl.dll ocpn_gltest1.exe source\buildwin\ocpn_gltest1.exe libpng16.dll source\buildwin\gtk\libpng16.dll cairo.dll source\buildwin\gtk\cairo.dll fontconfig.dll source\buildwin\gtk\fontconfig.dll iconv.dll source\buildwin\gtk\iconv.dll libxml2.dll source\buildwin\gtk\libxml2.dll pixman-1.dll source\buildwin\gtk\pixman-1.dll expat.dll source\buildwin\expat-2.1.0\expat.dll msvcp120.dll source\buildwin\vc\msvcp120.dll msvcr120.dll source\buildwin\vc\msvcr120.dll license.txt source\data\license.txt 16 wxWidget Files ----------------------------------------------------- Files From All Files source\buildwin\wxWidgets\*.* wxbase30u_net_vc_custom.dll (only for release) wxbase30u_vc_custom.dll (only for release) wxbase30u_xml_vc_custom.dll (only for release) wxmsw30u_adv_vc_custom.dll (only for release) wxmsw30u_aui_vc_custom.dll (only for release) wxmsw30u_core_vc_custom.dll (only for release) wxmsw30u_gl_vc_custom.dll (only for release) wxmsw30u_html_vc_custom.dll (only for release) wxmsw30u_media_vc_custom.dll (only for release) wxmsw30u_propgrid_vc_custom.dll (only for release) wxmsw30u_qa_vc_custom.dll (only for release) wxmsw30u_ribbon_vc_custom.dll (only for release) wxmsw30u_richtext_vc_custom.dll (only for release) wxmsw30u_stc_vc_custom.dll (only for release) wxmsw30u_webview_vc_custom.dll (only for release) wxmsw30u_xrc_vc_custom.dll (only for release) Crash Report ---------------------------------------------------------------------- Files From PrivacyPolicy.txt source\buildwin\crashrpt\PrivacyPolicy.txt CrashRpt1403.dll source\buildwin\crashrpt\CrashRpt1403.dll (only for release) crashrpt_lang.ini source\buildwin\crashrpt\crashrpt_lang.ini (only for release) CrashSender1403.exe source\buildwin\crashrpt\CrashSender1403.exe (only for release) dbghelp.dll source\buildwin\crashrpt\dbghelp.dll (only for release)
Copy the files (as noted above):
Thus bypassing installation.
Have you copied the necessary files as listed in 6.2 OR used the Batch Files in 6.1? Keep in mind what you're intent is, in running for the first time!
To run the [first time] issue the following command from a command prompt in the build/Debug or build/Release directory:
opencpn.exe /p
This will generate an opencpn.ini file in the current directory as well as create the opencpn.log file.
Note: opencpn.exe /p portable switch must be used every time otherwise when opencpn is used and we go to options > plugins there is an image format error, and the programdata\opencpn\opencpn.ini file is used.
Before getting desperate, read your openpcn.log logfile, it is likely that the problem is clearly identified there.